
module TN256_I2C_top(
	input        clk50M,
	input        irst_n,
	input        i_motor_en,
	input [1:0]  i_motor,
	inout        sda,
	output       sclk,
	output       ALSB   //ADR
			  );

  wire        clk100k_w;
  wire        wr_en_w;
  wire        rd_en_w;
  wire        wr_done_w;
  wire [23:0] idata_w;
  wire rst_n;
// assign  rst_n = 1'b1;
 reg rst_n_r;
 assign rst_n = rst_n_r;
 assign  ALSB  = ~i_motor_en;
 reg  [31:0] cnt;
 always@(posedge clk50M or negedge irst_n)
 begin
 if(~irst_n)
     begin
	 cnt <= 0;
     rst_n_r <= 1'b0;
	 end
else
    begin
	cnt <= (cnt < 49999999)?cnt+1:cnt;
    rst_n_r <= (cnt >= 49999999);
	end

 end

  clk100K clk100K_u(
              .clk50M     (clk50M),
              .rst_n      (rst_n),
				  .clk100k    (clk100k_w)
			     ); 
					
  I2C     I2C_u(
              .iclk       (clk100k_w),
              .rst_n      (rst_n),
			  .i_motor_en(i_motor_en),
			  .i_motor(i_motor),
			     .wr_en      (wr_en_w),
			     .rd_en      (rd_en_w),
			     .idata      (idata_w),
			     .sda        (sda),
			     .sclk       (sclk),
		        .wr_done    (wr_done_w)
//				  .rd_done    (rd_done),
//				  .rd_data_en (rd_data_en),
//			     .rd_data    (rd_data)
				  );
				  
  wr_gen  wr_gen_u(
              .clk100k    (clk100k_w),
              .rst_n      (rst_n),
				  .odata      (idata_w),
				  .wr         (wr_en_w),
				  .wr_done    (wr_done_w)
				  );
				  
endmodule